const fs = require('fs');
const path = require('path');

console.log(`This process is pid ${process.pid}`);

const pidfile = path.join(__dirname, 'run/app.pid');
fs.writeFileSync(pidfile, String(process.pid));

process.on('SIGTERM', function() {
    if (fs.existsSync(pidfile)) {
        console.log('deleting app.pid');
        fs.unlinkSync(pidfile);
    }

    console.log('see you later~');
    process.exit(0);
})

const http = require('http');
http.createServer((req, res) => {
    res.end('Hello, world!');
}).listen(3000);
